/*
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* openUBMC is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*         http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

#include <gtest/gtest.h>
#include <test_utilities/test_base.h>
#include "interface/optical_module/cooling.h"
#include <mc/engine.h>
#include <mc/common.h>
#include <ctime>

namespace drivers {
namespace pcie_nic_card {
namespace mellanox {
namespace interface {
namespace test {

class optical_module_cooling_test_service : public mc::engine::service {
public:
    optical_module_cooling_test_service(const std::string& name) : mc::engine::service(name) {}
};

// ========================= OpticalModule_Cooling测试 =========================
class OpticalModuleCoolingTest : public mc::test::TestWithEngine {
protected:
    static void SetUpTestSuite() {
        TestWithEngine::SetUpTestSuite();
        m_test_service = std::make_unique<optical_module_cooling_test_service>(
            "bmc.openubmc.test_optical_module_cooling");
        m_test_service->init();
        m_test_service->start();
    }
    static void TearDownTestSuite() {
        try {
            if (m_test_service) {
                m_test_service->stop();
                m_test_service.reset();
            }
            TestWithEngine::TearDownTestSuite();
        } catch (...) {
        }
    }
    void SetUp() override {
        m_cooling = mc::make_shared<dev::OpticalModule_Cooling>();
    }
    void TearDown() override {
        m_cooling.reset();
    }

    static std::unique_ptr<optical_module_cooling_test_service> m_test_service;
    mc::shared_ptr<dev::OpticalModule_Cooling>                 m_cooling;
};
std::unique_ptr<optical_module_cooling_test_service> OpticalModuleCoolingTest::m_test_service;

// ========================= 基本功能测试 =========================

TEST_F(OpticalModuleCoolingTest, Constructor) {
    dev::OpticalModule_Cooling cooling;
    EXPECT_TRUE(true);
}

TEST_F(OpticalModuleCoolingTest, Destructor) {
    {
        auto cooling = mc::make_shared<dev::OpticalModule_Cooling>();
        // 对象在这里析构
    }
    EXPECT_TRUE(true);
}

// ========================= 多实例测试 =========================

TEST_F(OpticalModuleCoolingTest, MultiInstance) {
    std::vector<mc::shared_ptr<dev::OpticalModule_Cooling>> coolings;
    for (int i = 0; i < 3; i++) {
        std::string object_name = "optical_module_cooling_" + std::to_string(i) + "_" +
                                  std::to_string(std::time(nullptr)) + "_" +
                                  std::to_string(i * 1000);
        std::string position = std::to_string(i + 21000);

        auto cooling = mc::make_shared<dev::OpticalModule_Cooling>();
        coolings.push_back(cooling);
    }

    for (auto& cooling : coolings) {
        // 清理
    }
    coolings.clear();
    EXPECT_TRUE(true);
}

// ========================= 基本操作测试 =========================

TEST_F(OpticalModuleCoolingTest, BasicOperations) {
    // 由于 OpticalModule_Cooling 目前没有其他方法，只测试基本操作
    EXPECT_TRUE(m_cooling != nullptr);
}

} // namespace test
} // namespace interface
} // namespace mellanox
} // namespace pcie_nic_card
} // namespace drivers

